﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.DataEntity;
using TimKen.BussLogic;
using System.Data;

namespace TimKen.Web.Admin.Customer
{
    public partial class Customer_List : TimKen.App.AdminPage
    {
        CustomerManager ctm = new CustomerManager();
        public override string ActionCode
        {
            get
            {
                return "92";//客户列表
            }
        }
        protected string OrderString
        {
            get
            {
                return (ViewState["OrderString"] == null) ? "CardCode" : Convert.ToString(ViewState["OrderString"]);
            }
            set
            {
                ViewState["OrderString"] = value;
            }
        }
        protected int OrderType
        {
            get
            {
                return (ViewState["OrderType"] == null) ? 0 : Convert.ToInt32(ViewState["OrderType"]);
            }
            set
            {
                ViewState["OrderType"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                     
                BindResources();
                BindData();
            }
        }

        public void BindResources()
        {          
            grdCustomer.Columns[0].HeaderText = GetLangString("CardCode");
            grdCustomer.Columns[1].HeaderText = GetLangString("CustomerForeignName");
            grdCustomer.Columns[2].HeaderText = GetLangString("CustomerName");
            grdCustomer.Columns[3].HeaderText = GetLangString("ContactPerson");
            grdCustomer.Columns[4].HeaderText = GetLangString("Telephone");   
            btnSearch.Text = GetLangString("Search");
        }

        protected void BindData()
        {
                    
            DataSet ds = ctm.GetPageList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, txtCustomerName.Text, txtCardCode.Text, OrderString, OrderType);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["total"]);
            this.grdCustomer.DataSource = ds;
            this.grdCustomer.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 0;
            BindData();
        }
        /// <summary>
        /// 排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdCustomer_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (OrderType==1)
            {
                OrderType = 0;
            }
            else
                OrderType = 1;
            OrderString = e.SortExpression;
            BindData();
        }    
    }
}
